package io.huaguoguo.nio;

import cn.hutool.http.HttpUtil;

import java.util.concurrent.*;

/**
 * 描述：  <br>
 * CreateDate: 2021/6/2 <br>
 *
 * @author huaguoguo
 */
public class HttpClient {

    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5,
                10,
                5L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1024));
        int c = 15;
        CountDownLatch count = new CountDownLatch(c);
        // 为什么只有五个线程在执行，没有扩容到10个线程
        for (int i = 0; i < c; i++) {
            poolExecutor.execute(() -> {
                try {
                    TimeUnit.SECONDS.sleep(2L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "111");
                count.countDown();
            });
        }
        count.await();
        ThreadFactory threadFactory = poolExecutor.getThreadFactory();
        TimeUnit.SECONDS.sleep(7L);
        System.out.println(threadFactory);
        String s = HttpUtil.get("http://127.0.0.1:8888/user?id=123&name=huaguoguo&group=aaa&group=bbb");
        System.out.println(s);
    }
}
